<template>
    <van-address-edit
    :address-info="data.addressInfo"
         show-delete
        show-set-default
        show-search-result
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        :show-area = "false"
          @save = 'onSave'


    />
</template>

<script setup>
import { userStore } from '@/store/userStore';
import { on } from 'events';
import { reactive } from 'vue';
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router'

const ustore = userStore()
const router = useRouter()
const route = useRoute()
const data = reactive({
  addressInfo:{}
})


//新增地址

//保存
function onSave(content) {
  console.address=content.addressDetail;
  if(route.query.type=='add'){
    ustore.addAddress(content)
    alert('保存成功')
  }else if(route.query.type=='edit'){
    ustore.editAddress(content)
    alert('修改成功')
  }

  setTimeout(() => {
    router.back()
  }, 1000)
}

//数据初始化
const init = () => {
  ustore.addressList.forEach(item => {
    if (item.id == route.query.id) {
      data.addressInfo = item
      data.addressInfo.addressDetail = item.address
    }
  })
}

onMounted(() => {
  init()
})

</script>


